package com.jari.lg.service.analysis.keyarea;

import com.jari.lg.domain.CheckPointHour;
import com.jari.lg.domain.DevBase;
import com.jari.lg.mapper.CheckPointHourMapper;
import com.jari.lg.utils.BaseData;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;

@Service
public class KeyAreaJamService {

    @Resource
    private CheckPointHourMapper checkPointHourMapper;


    @Scheduled(cron = "* * */1 * * ? ")
    private void CreateCheckPointHour() {
        List<CheckPointHour> ans = new ArrayList<>();

        List<DevBase> checkPoint = BaseData.checkpointList;
        for (DevBase d : checkPoint) {
            CheckPointHour checkPointHour = new CheckPointHour();
            checkPointHour.setCheckpointcode(d.getDevicecode());
            checkPointHour.setCheckpointname(d.getDevicename());
            checkPointHour.setPassingcarnum(new Random().nextInt(100));//每小时过车0-100
            checkPointHour.setDistrictpassingcarnum((int) (0.6 * checkPointHour.getPassingcarnum()));
            checkPointHour.setStartdatetime(new Date());
            checkPointHour.setLocalcarnum((int) (0.9 * checkPointHour.getDistrictpassingcarnum()));
            checkPointHour.setNolocalcarnum(checkPointHour.getDistrictpassingcarnum() - checkPointHour.getLocalcarnum());
            checkPointHour.setSmallcarnum((int) (0.65 * checkPointHour.getDistrictpassingcarnum()));
            checkPointHour.setBigcarnum(checkPointHour.getDistrictpassingcarnum() - checkPointHour.getSmallcarnum());
            checkPointHour.setPetrolcarnum((int) (0.85 * checkPointHour.getDistrictpassingcarnum()));
            checkPointHour.setElectriccarnum(checkPointHour.getDistrictpassingcarnum() - checkPointHour.getPetrolcarnum());
            checkPointHour.setNormalcarnum((int) (0.95 * checkPointHour.getDistrictpassingcarnum()));
            checkPointHour.setSpecialcarnum(checkPointHour.getDistrictpassingcarnum() - checkPointHour.getNormalcarnum());
            ans.add(checkPointHour);
        }
        //checkPointHourMapper.insertBatch(ans);
    }
}
